/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.helpdesk.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author JK
 */
@FacesValidator(value = "com.helpdesk.validators.CompareValidator")
public class CompareValidator implements javax.faces.validator.Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        UIInput password = (UIInput) context.getViewRoot().findComponent("txtpassword");
        String enteredPassword = (String) password.getSubmittedValue();
        if (((String) value).equals(enteredPassword)){
            FacesMessage msg = new FacesMessage("","");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            
            throw new ValidatorException(msg);
        }
    }
}
